/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.controller;


import cn.com.recloud.bbs.entity.bbs_contact;
import cn.com.recloud.bbs.service.ContactService;
import cn.com.recloud.bbs.service.MetaoptionService;
import cn.com.recloud.bbs.util.UserUtil;
import cn.com.recloud.core.util.Result;
import cn.com.recloud.one.spring.controller.BaseController;
import cn.com.recloud.one.spring.exception.OneException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author keblea xie
 * @date 2020-06-08
 */
@RestController
@RequestMapping("/api/bbs/contact")
@Api(tags = "小瑞联系人相关")
public class ContactController extends BaseController<bbs_contact,ContactService> {
    @Resource
    ContactService contactService;
    @Autowired
    private MetaoptionService metaoptionService;
    @Autowired
    private UserUtil userUtil;

    @GetMapping("info")
    @ApiOperation("获取当前用户信息")
    public Result currentContactInfo(){
        String userId = userUtil.getUserId();
        bbs_contact bbsContact = contactService.getById(userId);
        return new Result(bbsContact);
    }


    @PostMapping("updatename")
    @ApiOperation("修改用户昵称")
    public Result updateName(@RequestBody bbs_contact bbsContact){
        String userId = userUtil.getUserId();
        bbsContact.setBbs_contactid(userId);
        contactService.updateName(bbsContact);
        return Result.SUCCESS;
    }

    @PostMapping("saveorupdatecontact")
    @ApiOperation("保存或更新联系人信息")
    public Result saveOrUpdateContact(@RequestBody bbs_contact bbsContact){
        return new Result(contactService.updateOrSaveContact(bbsContact));
    }
}

